#include <stdio.h>
#include <string.h>
/*
    The following function calculates the checksum
    of a given array of data.
*/
unsigned char checksum(const void *buf, unsigned long cb)
{
    unsigned char ret;

    for (ret = 0; cb; cb--, buf++) {
	ret += *(const unsigned char *)buf;
    }

    return ret;
}

/*
    Calculate the zero checksum
 */
static unsigned char calchecksum(void *data, int len)
{
    int i;
    unsigned char sum = 0, *array = (unsigned char *)data;

    for (i = 0; i < len; i++)
    {
    	sum += array[i];
    }

    return ~sum+1;
}
